package com.bridgeintelligent.tag.mapper;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.entity.AssessInfo;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.AssessCombinationVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.AssessCustomersVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.DimAssessVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description
 * @author: grp 2020-09-03 14:28
 **/
@Mapper
public interface AssessMapper {
    @Select("select isrecommended,dim_id,dim_name,(select d_name from DIM_CLASSIFY where id=classify) as classify," +
            "(select d_name from DIM_DATA_SOURCE where id=data_source) as data_source,show_type,definition,caliber," +
            "scenarios,(select d_name from DIM_DEPARTMENT where id=business_department) as business_department," +
            "business_leader,upt_time,effective_time,dim_large_type,approve_date from  DIM_DATA where dim_id = " +
            "#{dimId}")
    DimAssessVO.DimBaseInfo findDimBaseInfo(String dimId);

    @Select("select id,day_type,combina_count,customer_count,search_count,dowload_count,update_date from  " +
            "fct_p_cust_bqpjtj_sycs " +
            "where DIM_ID = #{dimId} and IS_USED = '1' order by day_type asc")
    List<DimAssessVO.DimUseInfo> findDimUseInfo(String dimId);

    @Select("select * from  fct_p_cust_bqpjtj_summary " +
            "where col_name = #{dimId} order by update_date desc")
    List<DimAssessVO.DimQualityInfo> findDimQualityInfo(String dimId);


    @Select("select * from  DIM_FREE_BQZL " +
            "where col_name = #{dimId} order by update_date desc")
    List<DimAssessVO.DimQualityInfo> findDimFreeQualityInfo(String dimId);

    @Insert("INSERT INTO DIM_ASSESS_INFO VALUES (#{id}, #{dimId}, #{statCount}, #{assessDes}, #{moreTitle}, " +
            "#{createTime}, #{updateTime}, #{owner})")
    int saveAssessInfo(AssessInfo info);

    List<AssessCombinationVO> selectUsedDims(String id);

    List<AssessCustomersVO> selectUsedCustomers(String id);

    int updateAssessInfo(AssessInfo assessModel);
    @Select("select * from  DIM_ASSESS_INFO " +
            "where owner = #{owner} and dim_id = #{dimId}")
    AssessInfo selectByOwner(String owner, String dimId);

}
